<template>
<div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
    <el-form-item>
        <el-select
            v-model="searchObj.provinceCode"
            placeholder="请选择省"
                @change="provinceChanged">
            <el-option
                v-for="item in provinceList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"/>
        </el-select>
    </el-form-item>

<!--     <el-form-item>
        <el-select
        v-model="searchObj.cityCode"
        placeholder="请选择市"
        @change="cityChanged">
            <el-option
            v-for="item in cityList"
            :key="item.id"
            :label="item.name"
            :value="item.id"/>
        </el-select>
    </el-form-item> -->

    <el-form-item>
        <el-input v-model="searchObj.hosname" placeholder="医院名称"/>
    </el-form-item>

    <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
    <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

<!-- banner列表 -->
<el-table v-loading="listLoading" :data="list"
        border
      fit
      highlight-current-row>

     <el-table-column
      label="序号"
      type="index"
      width="50">
    </el-table-column>

    <el-table-column label="医院logo">
        <template slot-scope="scope">
        <img :src="'data:image/jpeg;base64,'+scope.row.logoData" width="80">
        </template>
    </el-table-column>

    <el-table-column prop="hosname" label="医院名称"/>
    <el-table-column prop="param.hostypeName" label="等级" width="90"/>
    <el-table-column prop="param.findAllAddress" label="详情地址"/>
    <el-table-column prop="status" label="状态" width="80">
        <template slot-scope="scope">
            <el-button v-if="scope.row.status == 0"  type="primary" size="mini">已下线</el-button>
            <el-button v-if="scope.row.status == 1"  type="danger" size="mini">已上线</el-button>
        </template>
    </el-table-column>
    <el-table-column prop="createTime" label="创建时间"/>

    <el-table-column label="操作" width="230" align="center">
         <template slot-scope="scope">
            <el-button v-if="scope.row.status == 1"  type="primary" size="mini" @click="updateStatus(scope.row.id, 0)">下线</el-button>
            <el-button v-if="scope.row.status == 0"  type="danger" size="mini" @click="updateStatus(scope.row.id, 1)">上线</el-button>
            <el-button type="danger" size="mini" @click="showDetail(scope.row.id)">详情</el-button>
            <router-link :to="'/hosp/hospital/schedule/'+scope.row.hoscode">
                <el-button type="primary" size="mini">排班</el-button>
            </router-link> 
        </template>
    </el-table-column>
</el-table>

    <!-- 分页组件 -->
    <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
    />
    <el-dialog
    title="医院详细信息"
    :visible.sync="centerDialogVisible"
    width="80%"
    center>
     <table v-loading="listLoading"  class="table table-striped table-condenseda table-bordered" width="100%">
        <tbody>
            <tr>
                <th width="10%">医院名称</th>
                <td width="40%"><b style="font-size: 14px">{{hospital.hosname }}</b> | {{hostypeName}}</td>
                <th width="10%">医院logo</th>
                <td width="35%">
                    <img :src="'data:image/jpeg;base64,'+hospital.logoData" width="80">
                </td>
            </tr>
            <tr>
                <th>医院编码</th>
                <td>{{ hospital.hoscode }}</td>
                <th>地址</th>
                <td>{{ findAllAddress}}</td>
            </tr>
            <tr>
                <th>坐车路线</th>
                <td colspan="8">{{ hospital.route }}</td>
            </tr>
            <tr>
                <th>医院简介</th>
                <td colspan="12">{{ hospital.intro }}</td>
            </tr>
        </tbody>
        </table>

        <h4>预约规则信息</h4>
        <table class="table table-striped table-condenseda table-bordered" width="100%">
        <tbody>
            <tr>
                <th width="15%">预约周期</th>
                <td width="35%">{{ bookingRule.cycle }}天</td>
                <th width="15%">放号时间</th>
                <td width="35%">{{ bookingRule.releaseTime }}</td>
            </tr>
            <tr>
                <th>停挂时间</th>
                <td>{{ bookingRule.stopTime }}</td>
                <th>退号时间</th>
                <td>{{ bookingRule.quitDay == -1 ? '就诊前一工作日' : '就诊当日' }}{{ bookingRule.quitTime }} 前取消</td>
            </tr>
            <tr>
                <th>预约规则</th>
                <td colspan="3">
                <ol>
                <li v-for="item in bookingRule.rule" :key="item">{{ item }}</li>
                </ol>
                </td>
            </tr>
        <br>
        </tbody>
    </table>
    <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="closeDialog">确 定</el-button>
    </span>
    </el-dialog>
</div>

</template>

<script>
import hospital from "@/api/hosp/hospital"
export default{
    // 定义变量和数值
    data(){
        return {
          listLoading: true, // 数据是否正在加载
          list: [], // banner列表
          total: 0, // 总记录数
          page: 1, // 默认页码
          limit: 10, // 每页记录数
          searchObj: {}, //查询表单对象
          provinceList: [],
          cityList: [],
          districtList: [],
          centerDialogVisible: false,
          hospital:[],
          bookingRule: {}, //预约信息
          hostypeName: null,
          findAllAddress: null
        }
    },
    // 创建生命周期函数：内存准备完毕，页面上为渲染
    created(){
        console.log('list created.....')
        this.fetchData()
        hospital.findByDictCode('Province').then(response=>{
            this.provinceList=response.data
        })
    },
    methods:{
        // 加载banner列表数据
        fetchData(page=1){
            console.log('翻页...'+page)
            // 异步获取远程数据
            this.page=page
            hospital.getPageList(this.page,this.limit,this.searchObj).then(response=>{
                console.log(response.data)
                this.list=response.data.content
                this.total=response.data.totalElements
                this.listLoading=false
            })
        },
        // 当页码发生改变时
        changeSize(size){
            console.log
            this.limit=size
            this.fetchData(1)
        },
        // 重置查询表单
        resetData(){
            console.log('重置查询表单')
            this.searchObj={}
            this.fetchData()
        },
        provinceChanged(){
            this.cityList=[],
            this.searchObj.cityCode=null
            this.districtList=[]
            this.searchObj.districtCode=null
            hospital.findByParentId(this.searchObj.provinceCode).then(response=>{
                this.cityList=response.data
            })
        },
        updateStatus(id, status) {
            hospital.updateStatus(id, status)
             .then(response => {
               this.fetchData(1)
           })
        },
        showDetail(id){
            this.centerDialogVisible = true
            hospital.getHospById(id)
                .then(response => {
                    console.log(response.data)
                    this.hospital = response.data.hospital
                    this.bookingRule = response.data.bookingRule
                    this.hostypeName=response.data.hospital.param.hostypeName
                    this.findAllAddress=response.data.hospital.param.findAllAddress
                })
        },
        closeDialog(){
            this.centerDialogVisible = false
        }
    }
}
</script>